home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-13 | 26.1 KB | 485 lines | [TEXT/KAHL] |
- /* Macintosh specific extensions */
-
- /* This file is intended to be used for the addition of Scheme procedures */
- /* to access machine specific features (such as Toolbox routines). */
-
- #include "os.h"
- #include "mem.h"
-
- #include "os_mac.h"
-
- #include "os_mac_Help.h"
-
- /*---------------------------------------------------------------------------*/
-
- void pascal_str( str, pstr ) /* utility to convert to Pascal string */
- SCM_obj str;
- Str255 pstr;
- { long i, len = SCM_length( str );
- if (len > 255) len = 255
- SetOrigin( (int)SCM_obj_to_int(h), (int)SCM_obj_to_int(v) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23backpat( port, pat )
- SCM_obj port, pat;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- BackPat( SCM_obj_to_str(pat) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23hidecursor()
- { HideCursor(); return (long)SCM_false; }
-
- SCM_obj mac_X23showcursor()
- { ShowCursor(); return (long)SCM_false; }
-
- SCM_obj mac_X23pensize( port, width, height )
- SCM_obj port, width, height;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- PenSize( (int)SCM_obj_to_int(width), (int)SCM_obj_to_int(height) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23penmode( port, mode )
- SCM_obj port, mode;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- PenMode( (int)SCM_obj_to_int(mode) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23penpat( port, pat )
- SCM_obj port, pat;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- PenPat( SCM_obj_to_str(pat) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23pennormal( port )
- SCM_obj port;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- PenNormal();
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23moveto( port, h, v )
- SCM_obj port, h, v;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- MoveTo( (int)SCM_obj_to_int(h), (int)SCM_obj_to_int(v) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23move( port, dh, dv )
- SCM_obj port, dh, dv;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- Move( (int)SCM_obj_to_int(dh), (int)SCM_obj_to_int(dv) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23lineto( port, h, v )
- SCM_obj port, h, v;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- LineTo( (int)SCM_obj_to_int(h), (int)SCM_obj_to_int(v) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23line( port, dh, dv )
- SCM_obj port, dh, dv;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- Line( (int)SCM_obj_to_int(dh), (int)SCM_obj_to_int(dv) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23textfont( port, font )
- SCM_obj port, font;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- TextFont( (int)SCM_obj_to_int(font) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23textface( port, face )
- SCM_obj port, face;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- TextFace( (int)SCM_obj_to_int(face) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23textmode( port, mode )
- SCM_obj port, mode;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- TextMode( (int)SCM_obj_to_int(mode) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23textsize( port, size )
- SCM_obj port, size;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- TextSize( (int)SCM_obj_to_int(size) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23spaceextra( port, extra )
- SCM_obj port, extra;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- SpaceExtra( (int)SCM_obj_to_int(extra) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23drawchar( port, ch ) /* ch is a Scheme character (a fixnum will also do!) */
- SCM_obj port, ch;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- DrawChar( (char)SCM_obj_to_int(ch) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23drawstring( port, s ) /* s is a Scheme string */
- SCM_obj port, s;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- DrawText( SCM_obj_to_str(s), 0, SCM_length(s) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23drawtext( port, textBuf, firstByte, byteCount ) /* textBuf is a Scheme string */
- SCM_obj port, textBuf, firstByte, byteCount;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- DrawText( SCM_obj_to_str(textBuf), (int)SCM_obj_to_int(firstByte), (int)SCM_obj_to_int(byteCount) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23charwidth( port, ch ) /* ch is a Scheme character (a fixnum will also do!) */
- SCM_obj port, ch;
- { long width;
- GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- width = CharWidth( (char)SCM_obj_to_int(ch) );
- SetPort( save );
- return SCM_int_to_obj( width );
- }
-
- SCM_obj mac_X23stringwidth( port, s ) /* s is a Scheme string */
- SCM_obj port, s;
- { long width;
- GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- width = TextWidth( SCM_obj_to_str(s), 0, SCM_length(s) );
- SetPort( save );
- return SCM_int_to_obj( width );
- }
-
- SCM_obj mac_X23textwidth( port, textBuf, firstByte, byteCount ) /* textBuf is a Scheme string */
- SCM_obj port, textBuf, firstByte, byteCount;
- { long width;
- GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- width = TextWidth( SCM_obj_to_str(textBuf), (int)SCM_obj_to_int(firstByte), (int)SCM_obj_to_int(byteCount) );
- SetPort( save );
- return SCM_int_to_obj( width );
- }
-
- SCM_obj mac_X23localtoglobal( port, pt )
- SCM_obj port, pt;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- LocalToGlobal( SCM_obj_to_str(pt) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23globaltolocal( port, pt )
- SCM_obj port, pt;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- GlobalToLocal( SCM_obj_to_str(pt) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23framerect( port, r )
- SCM_obj port, r;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- FrameRect( SCM_obj_to_str(r) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23paintrect( port, r )
- SCM_obj port, r;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- PaintRect( SCM_obj_to_str(r) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23eraserect( port, r )
- SCM_obj port, r;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- EraseRect( SCM_obj_to_str(r) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23invertrect( port, r )
- SCM_obj port, r;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- InvertRect( SCM_obj_to_str(r) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23fillrect( port, r, pat )
- SCM_obj port, r, pat;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- FillRect( SCM_obj_to_str(r), SCM_obj_to_str(pat) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23frameroundrect( port, r, ovWd, ovHt )
- SCM_obj port, r, ovWd, ovHt;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- FrameRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23paintroundrect( port, r, ovWd, ovHt )
- SCM_obj port, r, ovWd, ovHt;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- PaintRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23eraseroundrect( port, r, ovWd, ovHt )
- SCM_obj port, r, ovWd, ovHt;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- EraseRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23invertroundrect( port, r, ovWd, ovHt )
- SCM_obj port, r, ovWd, ovHt;
- { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
- InvertRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
- SetPort( save );
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23fillroundrect( port, r, ovWd, ovHt, pat )
- SCM_obj port, r, ovWd, ovHt, pat;
- { GrafPtr save; GetPort( &save ); SetPort icks;
- Delay( (long)SCM_obj_to_int(numTicks), &finalTicks );
- return SCM_int_to_obj( finalTicks );
- }
-
- SCM_obj mac_X23sysbeep( duration )
- SCM_obj duration;
- { SysBeep( (int)SCM_obj_to_int(duration) ); return (long)SCM_false; }
-
- SCM_obj mac_X23seteventmask( theMask )
- SCM_obj theMask;
- { SetEventMask( (int)SCM_obj_to_int(theMask) ); return (long)SCM_false; }
-
- SCM_obj mac_X23peek8( ptr )
- SCM_obj ptr;
- { return SCM_int_to_obj( (long)*((unsigned char *)SCM_obj_to_int(ptr)) ); }
-
- SCM_obj mac_X23poke8( ptr, val )
- SCM_obj ptr, val;
- { *((unsigned char *)SCM_obj_to_int(ptr)) = (unsigned char)SCM_obj_to_int(val);
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23peek16( ptr )
- SCM_obj ptr;
- { return SCM_int_to_obj( (long)*((short *)SCM_obj_to_int(ptr)) ); }
-
- SCM_obj mac_X23poke16( ptr, val )
- SCM_obj ptr, val;
- { *((short *)SCM_obj_to_int(ptr)) = (short)SCM_obj_to_int(val);
- return (long)SCM_false;
- }
-
- SCM_obj mac_X23peek32( ptr )
- SCM_obj ptr;
- { return SCM_int_to_obj( (long)*((long *)SCM_obj_to_int(ptr)) ); }
-
- SCM_obj mac_X23poke32( ptr, val )
- SCM_obj ptr, val;
- { *((long *)SCM_obj_to_int(ptr)) = (long)SCM_obj_to_int(val);
- return (long)SCM_false;
- }
-
- extern int edit( /* name, line, chr */ );
-
- SCM_obj mac_X23edit( name, line, chr)
- SCM_obj name, line, chr;
- { SCM_obj result;
- GrafPtr save;
- char pname[FILENAME_LEN];
- char path[FILENAME_LEN];
- char *p = SCM_obj_to_str(name);
- long len = SCM_length(name);
- int full_path = 0;
-
- if ((len == 0) || (len >= FILENAME_LEN)) return (long)SCM_false;
-
- GetPort( &save );
-
- pname[0] = len;
- path[len] = '\0';
- while (len > 0)
- { char c = p[len-1];
- if (c == ':') full_path = 1;
- pname[len] = c;
- len--;
- path[len] = c;
- }
-
- if ((full_path || getfullpathfromcurrentvolume( pname, path, FILENAME_LEN, 1 )) &&
- edit( path, SCM_obj_to_int(line), SCM_obj_to_int(chr) ))
- result = (long)SCM_true;
- else
- result = (long)SCM_false;
-
- SetPort( save );
-
- return result;
- }
-
- SCM_obj mac_X23help( str )
- SCM_obj str;
- { Str255 pstr;
- pascal_str( str, pstr );
- help_find( pstr );
- return (long)SCM_false;
- }
-
- /*---------------------------------------------------------------------------*/
-
-
- void ext_init()
- { DEFINE_C_PROC(mac_X23newwindow);
- DEFINE_C_PROC(mac_X23getnewwindow);
- DEFINE_C_PROC(mac_X23disposewindow);
- DEFINE_C_PROC(mac_X23setwtitle);
- DEFINE_C_PROC(mac_X23selectwindow);
- DEFINE_C_PROC(mac_X23hidewindow);
- DEFINE_C_PROC(mac_X23showwindow);
- DEFINE_C_PROC(mac_X23frontwindow);
- DEFINE_C_PROC(mac_X23findwindow);
- DEFINE_C_PROC(mac_X23trackgoaway);
- DEFINE_C_PROC(mac_X23dragwindow);
- DEFINE_C_PROC(mac_X23invalrect);
- DEFINE_C_PROC(mac_X23beginupdate);
- DEFINE_C_PROC(mac_X23endupdate);
-
- DEFINE_C_PROC(mac_X23openport);
- DEFINE_C_PROC(mac_X23initport);
- DEFINE_C_PROC(mac_X23closeport);
- DEFINE_C_PROC(mac_X23setport);
- DEFINE_C_PROC(mac_X23getport);
- DEFINE_C_PROC(mac_X23setorigin);
- DEFINE_C_PROC(mac_X23backpat);
- DEFINE_C_PROC(mac_X23hidecursor);
- DEFINE_C_PROC(mac_X23showcursor);
- DEFINE_C_PROC(mac_X23pensize);
- DEFINE_C_PROC(mac_X23penmode);
- DEFINE_C_PROC(mac_X23penpat);
- DEFINE_C_PROC(mac_X23pennormal);
- DEFINE_C_PROC(mac_X23moveto);
- DEFINE_C_PROC(mac_X23move);
- DEFINE_C_PROC(mac_X23lineto);
- DEFINE_C_PROC(mac_X23line);
- DEFINE_C_PROC(mac_X23textfont);
- DEFINE_C_PROC(mac_X23textface);
- DEFINE_C_PROC(mac_X23textmode);
- DEFINE_C_PROC(mac_X23textsize);
- DEFINE_C_PROC(mac_X23spaceextra);
- DEFINE_C_PROC(mac_X23drawchar);
- DEFINE_C_PROC(mac_X23drawstring);
- DEFINE_C_PROC(mac_X23drawtext);
- DEFINE_C_PROC(mac_X23charwidth);
- DEFINE_C_PROC(mac_X23stringwidth);
- DEFINE_C_PROC(mac_X23textwidth);
- DEFINE_C_PROC(mac_X23localtoglobal);
- DEFINE_C_PROC(mac_X23globaltolocal);
- DEFINE_C_PROC(mac_X23framerect);
- DEFINE_C_PROC(mac_X23paintrect);
- DEFINE_C_PROC(mac_X23eraserect);
- DEFINE_C_PROC(mac_X23invertrect);
- DEFINE_C_PROC(mac_X23fillrect);
- DEFINE_C_PROC(mac_X23frameroundrect);
- DEFINE_C_PROC(mac_X23paintroundrect);
- DEFINE_C_PROC(mac_X23eraseroundrect);
- DEFINE_C_PROC(mac_X23invertroundrect);
- DEFINE_C_PROC(mac_X23fillroundrect);
- DEFINE_C_PROC(mac_X23frameoval);
- DEFINE_C_PROC(mac_X23paintoval);
- DEFINE_C_PROC(mac_X23eraseoval);
- DEFINE_C_PROC(mac_X23invertoval);
- DEFINE_C_PROC(mac_X23filloval);
- DEFINE_C_PROC(mac_X23framearc);
- DEFINE_C_PROC(mac_X23paintarc);
- DEFINE_C_PROC(mac_X23erasearc);
- DEFINE_C_PROC(mac_X23invertarc);
- DEFINE_C_PROC(mac_X23fillarc);
-
- DEFINE_C_PROC(mac_X23newmenu);
- DEFINE_C_PROC(mac_X23getmenu);
- DEFINE_C_PROC(mac_X23disposemenu);
- DEFINE_C_PROC(mac_X23appendmenu);
- DEFINE_C_PROC(mac_X23addresmenu);
- DEFINE_C_PROC(mac_X23insertresmenu);
- DEFINE_C_PROC(mac_X23insertmenu);
- DEFINE_C_PROC(mac_X23drawmenubar);
- DEFINE_C_PROC(mac_X23deletemenu);
- DEFINE_C_PROC(mac_X23clearmenubar);
- DEFINE_C_PROC(mac_X23getnewmbar);
- DEFINE_C_PROC(mac_X23getmenubar);
- DEFINE_C_PROC(mac_X23setmenubar);
- DEFINE_C_PROC(mac_X23menuselect);
- DEFINE_C_PROC(mac_X23menukey);
- DEFINE_C_PROC(mac_X23hilitemenu);
- DEFINE_C_PROC(mac_X23disableitem);
- DEFINE_C_PROC(mac_X23enableitem);
- DEFINE_C_PROC(mac_X23getmhandle);
-
- DEFINE_C_PROC(mac_X23sfgetfile);
- DEFINE_C_PROC(mac_X23sfputfile);
-
- DEFINE_C_PROC(mac_X23getmouse);
- DEFINE_C_PROC(mac_X23button);
- DEFINE_C_PROC(mac_X23tickcount);
- DEFINE_C_PROC(mac_X23delay);
- DEFINE_C_PROC(mac_X23sysbeep);
- DEFINE_C_PROC(mac_X23seteventmask);
-
- DEFINE_C_PROC(mac_X23peek8);
- DEFINE_C_PROC(mac_X23poke8);
- DEFINE_C_PROC(mac_X23peek16);
- DEFINE_C_PROC(mac_X23poke16);
- DEFINE_C_PROC(mac_X23peek32);
- DEFINE_C_PROC(mac_X23poke32);
-
- DEFINE_C_PROC(mac_X23edit);
- DEFINE_C_PROC(mac_X23help);
- }
-
-
- /*---------------------------------------------------------------------------*/
-